
*Creates Table D.21

 use "$temp\old_young_temp.dta" , clear
 
 
 replace railway=(railway>0)
 
global municontrols  agrishare_1940 manushare_1940  town city railway high_income high_yos
global municontrols_cohort c.agrishare_1940#age44 c.manushare_1940#age44  city#age44 town#age44  railway#age44  high_income#age44  high_yos#age44 


/////////////////////////////////////
*-- heterogeneity baseline outcomes
/////////////////////////////////////


*You need the older cohorts for this part
*get education for older cohorts above 40
preserve
keep if age50>40
collapse  yos, by(muni_g)
rename yos yos_muni
sum yos_muni
tempfile edu
save `edu'
restore

drop _merge
joinby muni_g using `edu', unmatched(master)


gen high_income=(average_incometax_38>19.43981)
gen high_yos=(yos_muni> 6.622553)

gen bartik_rail=railway*bartik_standardized
gen bartik_income=high_income*bartik_standardized
gen bartik_yos=high_yos*bartik_standardized


tab age44



gen bartik_rail_young=railway*bartik_standardized*(age44<=25)
gen bartik_income_young=high_income*bartik_standardized*(age44<=25)
gen bartik_yos_young=high_yos*bartik_standardized*(age44<=25)



***
*Hdegree
***

reghdfe hdegree treat_young , a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store hde1
sum hdegree if vuosi==1970
estadd scalar ymean=r(mean)

reghdfe hdegree treat_young bartik_rail_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store hde2
sum hdegree if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe hdegree treat_young bartik_income_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store hde3
sum hdegree if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe hdegree treat_young bartik_yos_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store hde4
sum hdegree if vuosi==1970
estadd scalar ymean=r(mean)


***********
*YOS

******

reghdfe yos treat_young , a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store yos1
sum yos if vuosi==1970
estadd scalar ymean=r(mean)

reghdfe yos treat_young bartik_rail_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store yos2
sum yos if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe yos treat_young bartik_income_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store yos3
sum yos if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe yos treat_young bartik_yos_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store yos4
sum yos if vuosi==1970
estadd scalar ymean=r(mean)




***********
*white collar
******

reghdfe wc_ex treat_young , a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store wc_ex1
sum wc_ex if vuosi==1970
estadd scalar ymean=r(mean)

reghdfe wc_ex treat_young bartik_rail_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store wc_ex2
sum wc_ex if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe wc_ex treat_young bartik_income_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store wc_ex3
sum wc_ex if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe wc_ex treat_young bartik_yos_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store wc_ex4
sum wc_ex if vuosi==1970
estadd scalar ymean=r(mean)


***********
*executive
******

reghdfe higher_occ treat_young , a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store higher_occ1
sum higher_occ if vuosi==1970
estadd scalar ymean=r(mean)

reghdfe higher_occ treat_young bartik_rail_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store higher_occ2
sum wc_ex if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe higher_occ treat_young bartik_income_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store higher_occ3
sum higher_occ if vuosi==1970
estadd scalar ymean=r(mean)


reghdfe higher_occ treat_young bartik_yos_young, a(age44 age44#laani50 fem $municontrols_cohort muni_g ) cl(muni_g)
estadd local controls "\checkmark"
estadd local controls2 "\checkmark"
estadd local mfe "\checkmark"
estadd local cfe "\checkmark"
estadd local established "Yes"
estimates store higher_occ4
sum higher_occ if vuosi==1970
estadd scalar ymean=r(mean)






labe var treat_young "Exposure x Young"

labe var bartik_income_young "Exposure x High income x Young"
labe var bartik_rail_young "Exposure x Railway x Young"
labe var bartik_yos_young "Exposure x High Education x Young"


esttab yos1 yos2 yos3 yos4   hde1 hde2 hde3  hde4 ///
using "$temp\tables\TABLE_edu_young_hetero.tex", ///
mgroups(  "Years of Schooling"   "Higher degree"   , pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(treat_young bartik_yos_young bartik_income_young bartik_rail_young) nonotes ///s
b(%9.3f) se(%9.3f)  stats(N ymean established mfe cfe , fmt(0 3) layout(@ @ @) ///
labels("N"  "Y mean" "Established"    "Muni FE"  "Cohort FE")) label star(* .1 ** .05 *** .01) nodepvars nomtitle



esttab wc_ex1 wc_ex2 wc_ex3 wc_ex4  higher_occ1 higher_occ2 higher_occ3 higher_occ4 ///
using "$temp\tables\TABLE_occu_hetero.tex", ///
mgroups(  "White collar"   "Executive"   , pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(treat_young bartik_yos_young bartik_income_young bartik_rail_young) nonotes ///s
b(%9.3f) se(%9.3f)  stats(N ymean established mfe cfe , fmt(0 3) layout(@ @ @) ///
labels("N"  "Y mean" "Established"    "Muni FE"  "Cohort FE")) label star(* .1 ** .05 *** .01) nodepvars nomtitle




drop treat_young*

